﻿@{
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}
@model CodeOutput
<form class="layui-form layui-form-pane">
    @Html.AntiForgeryToken()
    <input type="hidden" name="Id" value="@Model.Id" />
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off" placeholder="请输入名称"
                   name="CodeText" value="@Model.CodeText" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数值</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off" placeholder="请输入数值"
                   name="CodeValue" value="@Model.CodeValue" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off"
                   name="CodeRemark" value="@Model.CodeRemark">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" class="layui-input" autocomplete="off" placeholder="请输入排序"
                   name="CodeSort" value="@{if (Model.CodeSort == null) { @Convert.ToString(0); } else {@Model.CodeSort }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            <input type="checkbox" name="IsEnable" value="true" lay-skin="switch"
                   lay-text="启用|禁用" lay-filter="isEnable" @{if (Model.IsEnable ?? true) { @Convert.ToString("checked")       ; } }>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否默认值</label>
        <div class="layui-input-block">
            <input type="checkbox" name="IsDefault" value="true" lay-skin="switch"
                   lay-text="是|否" lay-filter="IsDefault" @{if (Model.IsDefault ?? false) { @Convert.ToString("checked")       ; } }>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off"
                   name="CodeType" value="@ViewBag.CodeType" lay-verify="required" disabled="disabled">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级</label>
        <div class="layui-input-block">
            @Html.DropDownList("ParentId", ViewBag.CodeList as IEnumerable<SelectListItem>, new Dictionary<string, object> { { "lay-search", "" }, { "lay-verify", "required" }, { "lay-filter", "filter_ParentId" } })
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="Save">保存</button>
            <button type="button" class="layui-btn layui-btn-primary" id="btnCancel">取消</button>
        </div>
    </div>
</form>
@section scripts{
    <script type="text/javascript">
        var $, layer;
        layui.use(['form', 'upload'], function () {
            var form = layui.form;
            var upload = layui.upload;
            $ = layui.jquery;
            layer = parent.layer === undefined ? layui.layer : parent.layer;

            var postUrl = '@(Url.Action(Model.Id > 0 ? "Edit" : "Add", "Code"))';

            // 监听关闭
            $('#btnCancel').on('click', function () {
                layer_close();
            });

            // 监听提交
            form.on('submit(Save)', function (data) {
                var loading = layer.load();
                $.post(postUrl, data.field,
                    function (result) {
                        layer.close(loading);
                        if (result.Success) {
                            layer.msg(result.Message, { icon: 1, time: 2000 });
                            parent.reload();
                            layer_close();
                        } else {
                            layer.alert(result.Message, { icon: 2 });
                        }
                    });
                return false;
            })


        });
    </script>
}
